﻿using System;

namespace HuaCheng.CommonClass
{
    public class HexConvert
    {
        public static string BinaryToHex(string status)
        {
            string biString = status + "000";
            string hexString = "";
            for (int i = 0; i < biString.Length; i = i + 4)
            {
                string biCutStr = biString.Substring(i, 4);
                hexString += string.Format("{0:X}", System.Convert.ToInt32(biCutStr, 2));
            }
            return(hexString);
        }

        public static string HexToBinary(string hexString)
        {
            string biString = "";
            foreach (char c in hexString)
            {
                int v = Convert.ToInt32(c.ToString(), 16);
                int v2 = int.Parse(Convert.ToString(v, 2));
                biString += string.Format("{0:d4}", v2);
            }
            return(biString.Substring(0, 57));
        }
    }
}
